{% extends '/layout.html'%}

{% block title %}
    用户列表 | 小白鼠
{% endblock %}

{% block body %}
<h1>用户列表</h1>

<div>
    <table border="1">
        <tr>
            <th>用户名<a id="username" href="http://127.0.0.1:5000/users/all_users?page={{ pagination.page }}&select_type=username&order={{ order }}">∨</a></th>
            <th>姓名<a id="fullname" href="http://127.0.0.1:5000/users/all_users?page={{ pagination.page }}&select_type=fullname&order={{ order }}">∨</a></th>
            <th>创建时间<a id="created_time" href="http://127.0.0.1:5000/users/all_users?page={{ pagination.page }}&select_type=created_time&order={{ order }}">∨</a></th>
        </tr>
        {% for user in users %}
        <tr>
            <td>{{ user.username }}</td>
            <td>{{ user.fullname }}</td>
            <td>{{ user.created_time }}</td>
        </tr>
        {% endfor %}
    </table>


    {% if not pagination.page == 1 %}
    <a href="http://127.0.0.1:5000/users/all_users?page={{ pagination.page -1 }}&select_type=username&order=True">上一页</a>
    {% else %}
    <a href="http://127.0.0.1:5000/users/all_users?page=1&select_type=username&order=True">上一页</a>
    {% endif %}

    {% if not pagination.page == pagination.pages %}
    <a href="http://127.0.0.1:5000/users/all_users?page={{ pagination.page + 1 }}&select_type=username&order=True">下一页</a>
    {% else %}
    <a href="http://127.0.0.1:5000/users/all_users?page={{ pagination.pages }}&select_type=username&order=True">下一页</a>
    {% endif %}
    <li>第{{ pagination.page }}页</li>
    <li>共{{ pagination.pages }}页</li>


    <script>

    //等到页面元素加载成功
    $(document).ready(function () {
        //
        var order_username = $('#username').attr('href').toString().substr(-5);
        var order_fullname = $('#fullname').attr('href').toString().substr(-5);
        var order_created_time = $('#created_time').attr('href').toString().substr(-5);
        // alert(order);
        var flag_username = '';
        var flag_fullname = '';
        var flag_created_time = '';
        if (order_username == 'False'){
            // 排序按照的是reverse=True,降序∧
            flag_username = "∧";
        }else{
            // 排序按照的是reverse=False,升序∨
            flag_username = "∨";
        }
        $('#username').text(flag_username);

        if (order_fullname == 'False'){
            // 排序按照的是reverse=True,降序∧
            flag_fullname = "∧";
        }else{
            // 排序按照的是reverse=False,升序∨
            flag_fullname = "∨";
        }
        $('#fullname').text(flag_fullname);

        if (order_created_time == 'False'){
            // 排序按照的是reverse=True,降序∧
            flag_created_time = "∧";
        }else{
            // 排序按照的是reverse=False,升序∨
            flag_created_time = "∨";
        }
        $('#created_time').text(flag_created_time);
    });

</script>


</div>
{% endblock %}